package com.bucg.cjcloud.gb28181.sip.process;

import com.bucg.cjcloud.gb28181.sip.modle.ResponseModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.sip.message.Request;
import java.util.List;

public class DelegatingRequestProcess implements RequestProcess {
    private List<RequestProcess> requestProcessList;

    static Logger LOG = LoggerFactory.getLogger(DelegatingRequestProcess.class.getName());

    @Override
    public ResponseModel processRequest(Request req, String cmdType) {
        for (RequestProcess process : requestProcessList) {
            if (process.isSupport(req, cmdType)) {
                LOG.info(cmdType);
                return process.processRequest(req, cmdType);
            }
        }
        throw new RuntimeException();
    }

    @Override
    public boolean isSupport(Request req, String cmdType) {
        return true;
    }

    public DelegatingRequestProcess(List<RequestProcess> requestProcessList) {
        super();
        this.requestProcessList = requestProcessList;
    }

}
